<script setup>

import useWarehouseStore from '@/store/modules/warehouse'
import api from "./api";

const props = defineProps({
  /**当前双向数据绑定的值 */
  value: {
    type: [String, Number],
    default: ''
  },
});

const emit = defineEmits(['update:value']);

const warehouseStore = useWarehouseStore()
const list = ref(warehouseStore.getWarehouseList());

if (!list.value.length) {
  api.listAll().then((response)=>{
    warehouseStore.setWarehouseList(response)
    list.value = warehouseStore.getWarehouseList();
  })
}

const valueId = computed({
  get: () => props.value,
  set: (val) => {
    emit('update:value', val)
  }
});

</script>

<template>
  <el-select v-model="valueId" style="width: 100%;">
    <el-option v-for="u in list" :key="u.id" :label="u.warehouseName" :value="u.id"></el-option>
  </el-select>
</template>

<style scoped lang="scss">

</style>